﻿// (C) Copyright 2018 by Microsoft 
//
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Windows;
using System.Windows.Forms;
using System.Collections;
using cadApp = Autodesk.AutoCAD.ApplicationServices.Application;
using System.IO;
using common;
using YNCNumberSys.db;
// This line is not mandatory, but improves loading performances
[assembly: CommandClass(typeof(YNCNumberSys.MyCommands))]

namespace YNCNumberSys
{
    // This class is instantiated by AutoCAD for each document when
    // a command is called by the user the first time in the context
    // of a given document. In other words, non static data in this class
    // is implicitly per-document!
    public class MyCommands
    {
        // Modal Command with localized name
        [CommandMethod("MyGroup", "MyCommand", "MyCommandLocal", CommandFlags.Modal)]
        public void MyCommand() // This method can have any name
        {
            // Put your command code here

        }

        // Modal Command with pickfirst selection
        [CommandMethod("MyGroup", "MyPickFirst", "MyPickFirstLocal", CommandFlags.Modal | CommandFlags.UsePickSet)]
        public void MyPickFirst() // This method can have any name
        {
            PromptSelectionResult result = Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor.GetSelection();
            if (result.Status == PromptStatus.OK)
            {
                // There are selected entities
                // Put your command using pickfirst set code here
            }
            else
            {
                // There are no selected entities
                // Put your command code here
            }
        }

        // Application Session Command with localized name
        [CommandMethod("MyGroup", "MySessionCmd", "MySessionCmdLocal", CommandFlags.Modal | CommandFlags.Session)]
        public void MySessionCmd() // This method can have any name
        {
            // Put your command code here
        }

        // LispFunction is similar to CommandMethod but it creates a lisp 
        // callable function. Many return types are supported not just string
        // or integer.
        [LispFunction("MyLispFunction", "MyLispFunctionLocal")]
        public int MyLispFunction(ResultBuffer args) // This method can have any name
        {
            return 1;
        }

        [CommandMethod("XX", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void XX()
        {
            string filePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
            string file = Path.Combine(Path.GetDirectoryName(filePath), "config.ini");
            FileIni t = new FileIni(file);
            string regKey = t.ReadValue("配置", "数据库");
            if (!string.IsNullOrEmpty(regKey))
            {
                ConnectionManager.ConnectionStrings = regKey;
            }
            //读取AutoCAD的版本号，AutoCAD2020版本号23.01
            string str_version = Autodesk.AutoCAD.ApplicationServices.Core.Application.Version.ToString();
            //string[] strs=str_version.Split('.');
            //int i_version = Convert.ToInt32(strs[0]);
            //if (i_version<24)
            //{
            //    MyPlugin.RunYNC_Menu();
            //}
            MyPlugin.RunYNC_Menu();
        }
        /// <summary>
        /// 登录命令。
        /// </summary>
        [CommandMethod("LOGIN", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void LOGIN()
        {
            #region 增加登录信息Pane，菜单和工具条的控制
            bool has_pane = false;
            PaneCollection panes = cadApp.StatusBar.Panes;
            foreach (Pane pane in panes)
            {
                string paneName = pane.Text;
                if (paneName.Contains("当前用户"))
                    has_pane = true;
            }
            if (has_pane != true)
            {
                UsmLogInForm form = new UsmLogInForm();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                
                if (cadApp.ShowModalDialog
                    (
                    cadApp.MainWindow.Handle, 
                    form, 
                    false
                    ) == DialogResult.OK)
                {
                    Pane 登录信息Pane = new Pane();
                    登录信息Pane.Enabled = true;
                    登录信息Pane.Visible = true;
                    登录信息Pane.Style = PaneStyles.NoBorders;
                    登录信息Pane.Text = "当前用户:" + form.User.Name;//form.User.Code;
                    cadApp.StatusBar.Panes.Add(登录信息Pane);

                    Pane 登录IDPane = new Pane();
                    登录IDPane.Enabled = true;
                    登录IDPane.Visible = false;
                    登录IDPane.Style = PaneStyles.NoBorders;
                    登录IDPane.Text = "用户ID:" + form.User.Id.ToString();
                    cadApp.StatusBar.Panes.Add(登录IDPane);

                    MyPlugin.m_toolBar.b_登录 = false;
                    MyPlugin.m_toolBar.b_修改密码 = true;
                    if (form.User.Code == "admin")
                    {
                        MyPlugin.m_toolBar.b_用户管理 = true;
                        MyPlugin.m_toolBar.b_初始设置 = true;
                        MyPlugin.m_toolBar.b_Statistics = true;
                    }
                    else
                    {
                        MyPlugin.m_toolBar.b_Statistics = false;
                    }
                    MyPlugin.m_toolBar.b_图号管理 = true;
                    MyPlugin.m_toolBar.b_申请图号 = true;
                    MyPlugin.m_toolBar.b_4C有图申请 = true;
                    MyPlugin.m_toolBar.b_4C无图申请 = true;
                    MyPlugin.m_toolBar.b_外协图号申请 = true;
                    MyPlugin.m_toolBar.b_单个文件申请 = true;
                    MyPlugin.m_toolBar.b_图号查询 = true;
                    MyPlugin.m_toolBar.b_退出 = true;
                }
            }
            #endregion
        }

        [CommandMethod("LOGOUT", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void LOGOUT()
        {
            PaneCollection app所有Pane = cadApp.StatusBar.Panes;

            IEnumerator panEnum = app所有Pane.GetEnumerator();
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_名称 = appPane.Text;
                if (str_名称.IndexOf("当前用户") != -1)
                {
                    app所有Pane.Remove(appPane);
                    panEnum = app所有Pane.GetEnumerator();
                }
                if (str_名称.IndexOf("用户ID") != -1)
                {
                    app所有Pane.Remove(appPane);
                    panEnum = app所有Pane.GetEnumerator();
                }
            }

            cadApp.StatusBar.Update();
            cadApp.UpdateScreen();
            //acedShowDrawingStatusBars(false);

            MyPlugin.m_toolBar.b_登录 = true;
            MyPlugin.m_toolBar.b_修改密码 = false;
            MyPlugin.m_toolBar.b_用户管理 = false;
            MyPlugin.m_toolBar.b_初始设置 = false;
            MyPlugin.m_toolBar.b_申请图号 = false;
            MyPlugin.m_toolBar.b_图号管理 = false;
            MyPlugin.m_toolBar.b_4C有图申请 = false;
            MyPlugin.m_toolBar.b_4C无图申请 = false;
            MyPlugin.m_toolBar.b_外协图号申请 = false;
            MyPlugin.m_toolBar.b_单个文件申请 = false;
            MyPlugin.m_toolBar.b_图号查询 = false;
            MyPlugin.m_toolBar.b_Statistics = false;
            MyPlugin.m_toolBar.b_退出 = false;
        }
        /// <summary>
        /// 修改密码。
        /// </summary>
        [CommandMethod("PASSWORD", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void PASSWORD()
        {
            #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                //调用修改密码界面
                UsmPassWordForm form = new UsmPassWordForm();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.UserID = i_用户ID;

                if (cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false) == DialogResult.OK)
                {
                }
            }
        }
        /// <summary>
        /// [关于]
        /// </summary>
        [CommandMethod("ABOUTRP", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void ABOUTRP()
        {

            //CadHelper cad = new CadHelper();
            //cad.FineText();
            //return;
            AboutBox1 form = new AboutBox1();
            form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
            form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            form.MaximizeBox = false;
            form.MinimizeBox = false;
            form.ResumeLayout(false);
            form.DialogResult = DialogResult.None;
            if (cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false) == DialogResult.OK)
            {
            }
        }

        /// <summary>
        /// [关于]
        /// </summary>
        [CommandMethod("TEST", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void TEST()
        {

            CadHelper cad = new CadHelper();
            cad.FineText();
            return;
        }
        [CommandMethod("STATISTICS", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void STATISTICS()
        {
            StatisticsForm form = new StatisticsForm();
            form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            form.MaximizeBox = false;
            form.MinimizeBox = false;
            form.ResumeLayout(false);
            form.DialogResult = DialogResult.None;
            if (cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false) == DialogResult.OK)
            {
            }
        }
        /// <summary>
        /// [用户管理]
        /// </summary>
        [CommandMethod("INITUSER", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void INITUSER()
        {
             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                UsmInitUser form = new UsmInitUser();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
            }
        }

        [CommandMethod("INITSYSTEM", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void INITSYSTEM()
        {
             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                InitSystemForm form = new InitSystemForm();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
            }
        }
        /// <summary>
        /// 申请图号。
        /// </summary>
        [CommandMethod("APPLYNUMBER", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void APPLYNUMBER()
        {
            //DocumentCollection acDocMgr = cadApp.DocumentManager;
            //DialogResult result = DialogResult.Yes;
            //if (acDocMgr.Count > 0)
            //{
            //    result = MessageBox.Show("请确认要申请图号的图纸未被打开？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            //}
            //if (result!=DialogResult.Yes)
            //{
            //    return;
            //}

             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                ApplyNumber form = new ApplyNumber();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.str_用户名 = str_账户;

                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);

                MyPlugin.m_toolBar.s机床 = form.tbx_机床型号.Text;
                MyPlugin.m_toolBar.A号 = form.tbx_A号.Text;

            }
        }
        /// <summary>
        /// 内部没有操作数据库。
        /// </summary>
        [CommandMethod("NUMBERMANAGEMENT", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void NUMBERMANAGEMENT()
        {
             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                PaperManagementForm form = new PaperManagementForm();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = true;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.s_用户名 = str_账户;

                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
                //MyPlugin.m_toolBar.s机床 = form.tbx_机床型号.Text;
                //MyPlugin.m_toolBar.A号 = form.tbx_A号.Text;

            }
        }

        [CommandMethod("APPLY4CNUMBER", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void APPLY4CNUMBER()
        {
             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                Apply4CNumber form = new Apply4CNumber();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.str_用户名 = str_账户;

                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
                MyPlugin.m_toolBar.s机床 = form.tbx_机床型号.Text;
                MyPlugin.m_toolBar.A号 = form.tbx_A号.Text;

            }
        }

        [CommandMethod("APPLY4CNUMBERNODWG", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void APPLY4CNUMBERNODWG()
        {
             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                Apply4CNumberNoDwg form = new Apply4CNumberNoDwg();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.str_用户名 = str_账户;

                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
                MyPlugin.m_toolBar.s机床 = form.tbx_机床型号.Text;
                MyPlugin.m_toolBar.A号 = form.tbx_A号.Text;
            }
        }

        [CommandMethod("APPLYOUT", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void APPLYOUT()
        {
             #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                ApplyOut form = new ApplyOut();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.str_用户名 = str_账户;

                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
                //MyPlugin.m_toolBar.s机床 = form.tbx_机床型号.Text;
                //MyPlugin.m_toolBar.A号 = form.Text;

            }
        }

        [CommandMethod("APPLYSINGLE", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void APPLYSINGLE()
        {
            //DocumentCollection acDocMgr = cadApp.DocumentManager;
            //DialogResult result = DialogResult.Yes;
            //if (acDocMgr.Count > 0)
            //{
            //    result = MessageBox.Show("请确认要申请图号的图纸未被打开？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            //}
            //if (result!=DialogResult.Yes)
            //{
            //    return;
            //}

            #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                ApplySingle form = new ApplySingle();
                form.Text = "单个文件申请";
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = false;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.str_用户名 = str_账户;

                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
                MyPlugin.m_toolBar.s机床 = form.tbx_机床型号.Text;
                MyPlugin.m_toolBar.A号 = form.tbx_A号.Text;
            }
        }

        [CommandMethod("NUMBERQUERY", CommandFlags.Modal | CommandFlags.Redraw)]
        public static void NUMBERQUERY()
        {
            #region 遍历Pane,获取当前图纸账户和账户ID
            PaneCollection appPanes = cadApp.StatusBar.Panes;
            IEnumerator panEnum = appPanes.GetEnumerator();
            int i_用户ID = 0;
            string str_账户 = "";
            bool b_找到用户ID = false;
            bool b_找到用户账户 = false;
            while (panEnum.MoveNext())
            {
                Pane appPane = (Pane)panEnum.Current;
                string str_待解析串 = appPane.Text;
                if (!b_找到用户ID)
                {
                    if (-1 != str_待解析串.IndexOf("用户ID"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        i_用户ID = int.Parse(split[1]);
                        b_找到用户ID = true;
                    }
                }
                if (!b_找到用户账户)
                {
                    if (-1 != str_待解析串.IndexOf("当前用户:"))
                    {
                        string[] split = str_待解析串.Split(new Char[] { ':' });
                        str_账户 = split[1];
                        b_找到用户账户 = true;
                    }
                }
                if (b_找到用户ID && b_找到用户账户)
                    break;
            }
            #endregion

            if (b_找到用户ID)
            {
                PapercodeQueryForm form = new PapercodeQueryForm();
                form.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
                //form.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                form.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                form.MaximizeBox = true;
                form.MinimizeBox = false;
                form.ResumeLayout(false);
                form.DialogResult = DialogResult.None;
                form.str_用户名 = str_账户;
                form.str_机床=MyPlugin.m_toolBar.s机床;
                form.str_A号 = MyPlugin.m_toolBar.A号;
                cadApp.ShowModalDialog(cadApp.MainWindow.Handle, form, false);
            }
        }
    }

}
